<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>vue 学习 1-3</title>
    <script src="https://cdn.jsdelivr.net/npm/vue/dist/vue.js"></script>
    <script src="https://cdn.jsdelivr.net/npm/axios@0.12.0/dist/axios.min.js"></script>
    <script src="https://cdn.jsdelivr.net/npm/lodash@4.13.1/lodash.min.js"></script>
</head>

<body>
    <h2>条件渲染</h2>
    <div id="app">
        <!-- v-if和v-else的使用 -->
        <h1 v-if="awesome">Vue is awesome!</h1>
        <h1 v-if="awesome">Vue is awesome!</h1>
        <h1 v-else>Oh no 😢</h1>
        <!-- 放到template里面将不显示template标签 -->
        <template v-if="ok">
            <h1>Title</h1>
            <p>Paragraph 1</p>
            <p>Paragraph 2</p>
        </template>
        <!-- v-else-if来表示连续的else if语块 -->
        <div v-if="type === 'A'">
            A
        </div>
        <div v-else-if="type === 'B'">
            B
        </div>
        <div v-else-if="type === 'C'">
            C
        </div>
        <div v-else>
            Not A/B/C
        </div>

        <div v-if="loginType === 'username'">
            <label>Username</label>
            <input placeholder="Enter your username">
        </div>
        <div v-else>
            <label>Email</label>
            <input placeholder="Enter your email address">
        </div>

        <div v-if="loginType === 'username'">
            <label>Username</label>
            <input placeholder="Enter your username" key="username-input">
        </div>
        <div v-else>
            <label>Email</label>
            <input placeholder="Enter your email address" key="email-input">
        </div>
        <button @click="toggleLoginType">Toggle login type</button>

        <h1 v-show="ok">Hello!</h1>
    </div>
</body>

<script>
    var vm = new Vue({
        el: "#app",
        data: {
            awesome: true,
            ok: true,
            type: "A",
            loginType: 'username'
        },
        methods: {
            toggleLoginType: function () {
                return this.loginType = this.loginType === 'username' ? 'email' : 'username'
            }
        }
    })

</script>

</html>